package com.computergames.server.service.GameStrategy;

import com.computergames.server.message.MoveRequestMessage;
import com.computergames.server.service.Implement.GobangMessageHandlerFactory;
import com.computergames.server.service.Interface.GameMessageHandlerFactory;
import com.computergames.server.util.SpringUtil;
import io.netty.channel.ChannelHandlerContext;

import java.util.Set;


public class GobangMessageHandler implements MessageHandlingStrategy{
    @Override
    public int handle(MoveRequestMessage msg, String roomName, ChannelHandlerContext ctx) {
        GameMessageHandlerFactory gobangMessageHandlerFactory = SpringUtil.getBean(GobangMessageHandlerFactory.class);
        int result = gobangMessageHandlerFactory.getRuleDetermination().ruleDetermination(roomName, msg.getContent(), ctx);
        gobangMessageHandlerFactory.getGameStorage().save(roomName, msg.getContent(), result, ctx);
        return result;
    }
}
